package com.runchinaup.smartbelt.receiver;

import android.content.Context;
import android.content.SharedPreferences;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.runchinaup.smartbelt.App;
import com.runchinaup.smartbelt.ble.BlueGattCallbackHelper;


/**
 * Created by liber on 2018/2/5.
 */

public class MyPhoneStateListener extends PhoneStateListener {

    private BlueGattCallbackHelper gattCallbackHelper = BlueGattCallbackHelper.getBlueGattCallbackHelper();

    @Override
    public void onCallStateChanged(int state, String incomingNumber) {

        switch (state) {
            case TelephonyManager.CALL_STATE_IDLE://非通话状态
                android.util.Log.i("debug_call_phone", "手机空闲起来了");
                if (!TextUtils.isEmpty(incomingNumber)) {
//                    helper.phoneCallRemind(phone, App.getApp());
                }
                break;
            case TelephonyManager.CALL_STATE_RINGING:
                android.util.Log.i("debug_call_phone", " 手机铃声响了，来电号码:" + incomingNumber);
                SharedPreferences shared = App.getApp().getSharedPreferences("buttonIsOpen", Context.MODE_PRIVATE);
                if (shared.getBoolean("isCall", false)) {
                    gattCallbackHelper.phoneCallRemind();
                }
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK://接通或者去电状态
                android.util.Log.i("debug_call_phone", "电话被挂起了");
//                helper.phoneCallRemind(phone, App.getApp());
            default:
                break;

        }

        super.onCallStateChanged(state, incomingNumber);
    }
}
